<?php

namespace App\Repositories\Criteria;

use Illuminate\Http\Request;
use Prettus\Repository\Contracts\CriteriaInterface;
use Prettus\Repository\Contracts\RepositoryInterface;

/**
 * Class OrderStatusCriteria
 * @package namespace App\Repositories\Criteria;
 */
class OrderStatusCriteria implements CriteriaInterface
{
    protected $status;
    protected $field;

    public function __construct($status, $field)
    {
        $this->status = $status;
        $this->field = $field;
    }

    /**
     * Apply criteria in query repository
     *
     * @param                     $model
     * @param RepositoryInterface $repository
     *
     * @return mixed
     */
    public function apply($model, RepositoryInterface $repository)
    {
        if ($this->status != 99) {
            return $model->where($this->field, $this->status);
        }
        return $model;
    }
}
